<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text">
    <button class="set">存储数据</button>
    <button class="get">读取数据</button>
    <button class="remove">删除数据</button>
    <button class="del">清空数据</button>
    <script>
        var input = document.querySelector('input');
        var set = document.querySelector('.set');
        set.addEventListener('click', function() {
            //当点击之后就存储值
            var val = input.value;
            sessionStorage.setItem('uname', val);
        })
        var get = document.querySelector('.get');
        get.addEventListener('click', function() {
            //点击之后获取值
            console.log(sessionStorage.getItem('uname'));
        })
        var rem = document.querySelector('.remove');
        rem.addEventListener('click', function() {
            //点击之后删除值
            console.log(sessionStorage.removeItem('uname'));
        })
    </script>
</body>

</html>